package com.cgwx.common.utils;

import org.apache.commons.lang.RandomStringUtils;

import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.concurrent.ThreadLocalRandom;

public class GeneratorId {


    private static final SimpleDateFormat dateFormatOne=new SimpleDateFormat("yyyyMMddHHmmssSS");
    private static final ThreadLocalRandom random= ThreadLocalRandom.current();

    //时间戳+N为随机数流水号
    public static String generateOrderCode(String featureStr){
        return dateFormatOne.format(new Date().getTime()) + "_"+generateNumber(5)+ "_"+featureStr;
    }

    public static String generateNumber(final int num){
        StringBuffer sb=new StringBuffer();
        for (int i=1;i<=num;i++){
            sb.append(random.nextInt(9));
        }
        return sb.toString();
    }
    public static String generateFileId(){
        return DateUtils.getCurrentTime(DateUtils.YY_MM_DD_HH_MM_SS_SSS_PATTERN) + RandomStringUtils.randomAlphanumeric(5);
    }

    public static String generateId(String featureStr){
        return featureStr + DateUtils.getCurrentTime(DateUtils.YY_MM_DD_HH_MM_SS_SSS_PATTERN) + RandomStringUtils.randomAlphanumeric(5);
    }
}
